package com.health.userbackstage.web.control;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.health.userbackstage.pojo.Order;
import com.health.userbackstage.pojo.OrderSetting;
import com.health.userbackstage.pojo.SetMeal;
import com.health.userbackstage.pojo.result.Result;
import com.health.userbackstage.pojo.result.ResultEnum;
import com.health.userbackstage.service.MemberService;
import com.health.userbackstage.service.OrderService;
import com.health.userbackstage.service.OrderSettingService;
import com.health.userbackstage.service.SetMealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Author ASUS
 * @Date 2023/8/22 9:24
 * @Version 1.0
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderSettingService oss;

    @Autowired
    private OrderService os;

    @Autowired
    private SetMealService sms;

    @Autowired
    private MemberService ms;

    @Autowired
    private SimpleDateFormat sdf;

    @RequestMapping("getMembers")
    public Result getMembers() {
        return Result.success(ms.list());
    }

    @RequestMapping("getSetMeals")
    public Result getSetMeals() {
        return Result.success(sms.list());
    }

    @RequestMapping("getOrderDates")
    public Result getOrderDates() {
        return Result.success(oss.getOrderDates());
    }

    @RequestMapping("/findpage")
    private Result findPage(@RequestBody Order order) {
        System.out.println(order.getCurrentPage());
        return Result.success(os.findPage(order.getCurrentPage(), order.getPageSize(), order.getQueryString(),order.getQueryDate()));
    }

    @RequestMapping("/add")
    private Result add(@RequestBody Order order) {
        if(os.add(order)){
            return Result.success();
        }else {
            return Result.fail("该日已经预约满了");
        }
    }

    @RequestMapping("/edit")
    private Result edit(@RequestBody Order order) {
        if(os.edit(order)){
            return Result.success();
        }else {
            return Result.fail("该日已经预约满了");
        }
    }

    @RequestMapping("/del")
    private Result del(@RequestBody Order order) {
       os.del(order.getId());
       return Result.success();
    }
}
